home *** CD-ROM | disk | FTP | other *** search
/ SunSoft Catalyst CDWARE 1996 May to August / Catalyst CDWARE 1996 May to August.iso / .products / .bin / httpd / Solaris_2 / brandnewwais.pl.bk < prev    next >
Text File  |  1996-02-15  |  6KB  |  212 lines

  1. #!./perl
  2. #
  3. # newwais.pl -- WAIS search interface
  4. #
  5. # from wais.pl
  6. #
  7. # Tony Sanders <sanders@bsdi.com>, Nov 1993
  8. #
  9. # Example configuration (in local.conf):
  10. #     map topdir wais.pl &do_wais($top, $path, $query, "database", "title")
  11. #
  12. # this script uses a sneaky feature of Mosaic that interpretes a 
  13. # single text input form with the name 'isindex' (case sensitive) to
  14. # the same as a <ISINDEX>.  On non-mosaic clients, you wind up with an
  15. # additional query
  16. #
  17. # Note that I know even less about perl than the other two people
  18. # who hacked this, so feel free to send hate mail to pjh@netcom.com
  19. # if I did something really bad (or if there is a better way of
  20. # grabbing the filename off the end of a path.
  21. #
  22.  
  23. $oldLIB = $ENV{"LD_LIBRARY_PATH"}; 
  24. $ENV{"LD_LIBRARY_PATH"} = "$oldLIB:/usr/ucblib"; 
  25.  
  26.  
  27. #require 'ctime.pl';
  28.  
  29. $waisq = "./waisq";
  30. $waisd = "/tmp/.wais/wais_CDware";
  31.  
  32.  
  33. $src = "wais_CDware";
  34. $title = "Example Data";
  35. #
  36. # file type map based on file extension, since all file types
  37. # come back type URL
  38. #
  39.  
  40. %filetype = (
  41. 'html', 'HTML File', 'ps', 'PostScript  Document',
  42. 'htm', 'HTML File', 'eps', 'PostScript  Document',
  43. 'txt','Text File', 'home', 'Home Page on Business Solution CD'
  44. );
  45.  
  46. #
  47. # code
  48. sub send_index {
  49.     print "Content-type: text/html\n\n";
  50.     
  51.     print "<HEAD>\n<TITLE>Index of ", $title, "</TITLE>\n</HEAD>\n";
  52.     print "<BODY>\n<H1>", $title, "</H1>\n";
  53.  
  54.     print "This is an index of the information on this server. Please\n";
  55.     print "type a query in the search dialog.\n<P>";
  56.     print "You may use compound searches, such as: <CODE>environment AND cgi</CODE>\n";
  57.     print "<ISINDEX>";
  58. }
  59.  
  60.  
  61. sub do_wais {
  62. #    local($top, $path, $query, $src, $title) = @_;
  63.  
  64. # parse stream
  65.  
  66.  
  67.     for (@_){s/\\//g};
  68.  
  69.     local(@query) = @_;
  70.     local($pquery) = join(" ", @query);
  71.     local($nquery) = $pquery;
  72.     $nquery =~ tr/[A-Z]/[a-z]/;
  73.     if (!(($nquery =~ / and /) || ($nquery =~ / or /)))
  74.     {
  75.        $nquery =~ s/ //g;
  76.     }
  77. #
  78. # grab a wais source if there is one
  79. #
  80.  
  81.     local($test) = $ENV{'PATH_INFO'};
  82.     if ($test)
  83.     {
  84.     $test =~ s/\///;
  85.         $src = "wais_CDware";
  86.         $title = $test;
  87.     }
  88.  
  89.     close STDERR;
  90.     open(STDERR, ">/dev/null");
  91.  
  92.     print "Content-type: text/html\n\n";
  93.  
  94.     $ENV{'HOME'} = "/";
  95.     
  96.     open(WAISQ, "-|") || exec ($waisq, "-c", $waisd, "-m", 100,
  97.                                 "-f", "-", "-S", "$src.src", "-g", $nquery);
  98.  
  99.     print "<HEAD>\n<TITLE>Search of ", $title, "</TITLE>\n</HEAD>\n";
  100.     print "<img src=\"/.wais/images/goto_home.gif\">\n";
  101.     print "<BODY>\n<H1>CDware Search Results</H1>\n";
  102.  
  103.     print "<HR><FORM method=\"POST\" action=\"/cgi-bin/brandnewwais.pl/$src\">\n";
  104.     print "Enter keyword(s):\n";
  105. #    print "<input name=\"isindex\" value=\"@query\" size=30></FORM><HR>\n";
  106.     print "<input name=\"isindex\" value=\"$pquery\" size=30></FORM><HR>\n";
  107.  
  108.     print "$title contains the following\n";
  109.     print "items relevant to <B>\`$pquery\':</B><P>\n";
  110.     print "<DL>\n";
  111.  
  112.     #local($hits, $score, $headline, $lines, $bytes, $type, $date);
  113.     local($hits, $score, $lines, $bytes, $type, $date);
  114.  
  115. $hits = -1;
  116.     print "<OL>";
  117.     while (<WAISQ>) {
  118.         /:score\s+(\d+)/ && ($score = $1);
  119.         /:number-of-lines\s+(\d+)/ && ($lines = $1);
  120.         /:number-of-bytes\s+(\d+)/ && ($bytes = $1);
  121.         /:type "(.*)"/ && ($type = $1);
  122.         /:headline "(.*)"/ && ($headline = $1);         # XXX
  123.         /:date "(\d+)"/ && ($date = $1, $hits++, &docdone);
  124.     }
  125.     &display;
  126.     print "</OL>";
  127.     close(WAISQ);
  128.     print "</DL>\n";
  129.  
  130.     print "</BODY>\n";
  131. }
  132.  
  133.  
  134.  
  135.  
  136.  
  137. #
  138. # THis sub was set up to grab the context of the string.
  139. # It needs to be emplemented
  140. #
  141. sub display {
  142.     for ($i = 0; $i <= $length_context - 1; $i++ ) {
  143.     @tmp = split(/,/,@pcontext[$i]);
  144.     $href = @tmp[1];
  145.     $name = @tmp[0];
  146.     $ext = @tmp[3];
  147.        $filename = $href;
  148.        $filename =~ s/file:\/\///;
  149.        #$filename =~ s/\/([^\/]*)$//;
  150.        #$filename = $1;
  151.  
  152.         print "<LI><A HREF=\"$href\"><B><b>$name</B></b></A>";
  153.         print "        <b>$filetype{$ext}</b>\n";
  154. #        open(IN,$filename) || die "howdy";
  155. #        while (<IN>) { 
  156. #                        if ( $_ =~ /$pquery/i ){
  157.             #$temporary = $_;
  158.             #$temporary = s/[^.*$pquery]*$//i;
  159.             #$temporary = $_;
  160.                         #print "$temporary<b>;</b><br>";
  161. #                        }
  162. #        }
  163. #        close(IN);
  164.  
  165.     }
  166. }
  167.  
  168.  
  169. sub docdone {
  170.  
  171.     if ($headline =~ /Search produced no result/) {
  172.         print "<HR>";
  173.     print "Search produced no result.";
  174.     print "<p>Test<p>";
  175.     print $Test;
  176. #        print $headline, "<P>\n<PRE>";
  177. # the following was &'safeopen
  178. #        open(WAISCAT, "$waisd/$src.cat") || die "$src.cat: $!";
  179. #        while (<WAISCAT>) {
  180. #            s#(Catalog for database:)\s+.*#$1 <STRONG>Catalyst Catalog on CDware</STRONG>#;
  181. #            s#Headline:\s+(.*)#Headline: <A HREF="$1">$1</A>#;
  182. #            print;
  183. #        }
  184. #        close(WAISCAT);
  185. #        print "\n</PRE>\n";
  186.     } else {
  187.         $docname = $headline;
  188.     $docname =~ s/\.([^.]*)$//;
  189.     $extension= $1;
  190.     $docname =~ s/\/([^\/]*)$//;
  191.     $docname = $1;
  192.     if ($docname =~ "^index") {
  193.         $docname = $headline;
  194.             $docname =~ s/\/([^\/]*)$//;
  195.             $docname =~ s/\/([^\/]*)$//;
  196.         $docname = $1;
  197.         $extension = "home";
  198.         } else {
  199.         $docname = $1;
  200.     }
  201.     @context = ($docname,$headline,$filetype,$extension);
  202.     @pcontext[$hits] = join (",", @context); 
  203.     
  204.     }
  205.     $length_context = @pcontext;
  206.     
  207.     $score = $headline = $lines = $bytes = $type = $date = '';
  208. }
  209.  
  210. eval '&do_wais';
  211.